<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid布局</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            display: grid;
            grid-template-columns: repeat(auto-fill, 20%);
            grid-template-rows: repeat(auto-fill, 200px);
        }

        .box p {
            text-align: center;
            line-height: 100px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div style="background-color: #f00;">
            <p>1</p>
        </div>
        <div style="background-color: rgb(36, 170, 103);">
            <p>2</p>
        </div>
        <div style="background-color: rgb(26, 56, 224);">
            <p>3</p>
        </div>
        <div style="background-color: rgb(219, 17, 17);">
            <p>4</p>
        </div>
    </div>

</body>

</html>